#include <iostream>
#include <string.h>
#include <math.h>
using namespace std;


int main(){
	string a,b;
	cin>>a>>b;
	int al=a.length(),bl=b.length();
	int k;
	cin>>k;
	int dp[al+1][bl+1];
	dp[0][0] = 0;
	for(int i=1;i<=al;i++)
		dp[i][0] = dp[i-1][0]+k;
	for(int i=1;i<=bl;i++)
		dp[0][i] = dp[0][i-1]+k;
	for(int i=1;i<=al;i++){
		for(int j=1;j<=bl;j++){
			dp[i][j] = min(dp[i-1][j-1]+abs(a[i-1]-b[j-1]),min(dp[i-1][j]+k,dp[i][j-1]+k));
//			cout<<dp[i][j]<<" ";
		}
//		cout<<endl;
	}
	cout<<dp[al][bl];
	return 0;
}
